import { Component, OnInit } from '@angular/core';
import { SystemConfigService } from '@core/services/system-config.service';

import { FormBuilder, FormGroup, Validators } from '@angular/forms';

@Component({
  selector: 'app-system-msg',
  templateUrl: './system-msg.component.html',
  styleUrls: ['./system-msg.component.less']
})
export class SystemMsgComponent implements OnInit {
  public myGroup: FormGroup;
  public cnName: any;
  public sysInfos: any = {
    cnName: '',
    enName: '',
    version: '',
    name: '',
    ip: '',
    port: '',
    url: '',
    copyRight: '',
    sysType: ''
  };
  public sysTypes: any;
  public isConfirmLoading = false;

  constructor(private systemService: SystemConfigService, private fb: FormBuilder) { }

  submit() {
    this.systemService.sysMsgUpdate(this.sysInfos).then((data: any) => {
      this.isConfirmLoading = false;
    }, data => {
    });
  }

  ngOnInit() {
    console.log(this.myGroup);
    this.myGroup = this.fb.group({
      cnName: [ null, [ Validators.required ] ],
      enName: [ null, [ Validators.required ] ],
      version: [ null ],
      name: [ null, [ Validators.required ] ],
      ip: [ null ],
      port: [ null ],
      url: [ null, [ Validators.required ] ],
      copyRight: [ null, [ Validators.required ] ],
      sysType: [ null, [ Validators.required ] ]
    });
    this.systemService.getSys().then((data: any) => {
      // this.myGroup.patchValue({
      //   cnName: data.data.cnName
      // });
      // console.log(this.myGroup);
      this.sysInfos = data.data;
      this.sysInfos.sysType = this.sysInfos.sysType.toString();
    }, data => {
    });

    this.systemService.getSysType().then((data: any) => {
      this.sysTypes = data.data.content;
    }, data => {
    });
  }
}
